﻿<%@ WebHandler Language="C#" Class="jupload" %>
using System;
using System.Web;
using System.IO;

public class jupload : IHttpHandler{

    public void ProcessRequest(HttpContext context)
    {
        context.Response.ContentType = "text/plain";
        context.Response.Charset = "utf-8";
        HttpPostedFile getFile = context.Request.Files["Filedata"];
        string uploadPath = HttpContext.Current.Server.MapPath("~/gupload/docfiles/");       
        if (getFile != null)
        {
            string iFileName=Path.GetFileNameWithoutExtension(getFile.FileName);
            string iFileType=Path.GetExtension(getFile.FileName);
            string newFileName = string.Format("{0}_{1}{2}", iFileName, DateTime.Now.ToString("yyyyMMddHHmmff"), iFileType);
            
            if (!Directory.Exists(uploadPath))
            {
                Directory.CreateDirectory(uploadPath);
            }
            getFile.SaveAs(string.Format("{0}{1}",uploadPath,newFileName));
            //下面这句代码缺少的话，上传成功后上传队列的显示不会自动消失
            context.Response.Write("1,"+newFileName);
        }
        else
        {
            context.Response.Write("0");
        }
    }
    public bool IsReusable
    {
        get
        {
            return false;
        }
    }
}
